/*
 *    Copyright (c) 2017 ADTEC
 *    All rights reserved
 *
 *    本程序为自由软件；您可依据自由软件基金会所发表的GNU通用公共授权条款规定，就本程序再为发布与／或修改；无论您依据的是本授权的第二版或（您自行选择的）任一日后发行的版本。
 *    本程序是基于使用目的而加以发布，然而不负任何担保责任；亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
 */

package com.nxy.cpfsfe;

import com.adtec.starring.data.ibatis.IBaseDos;
import com.adtec.starring.datapool.CompSDO;
import com.adtec.starring.datapool.EPOper;
import com.adtec.starring.exception.BaseException;
import com.adtec.starring.log.TrcLog;
import com.adtec.starring.respool.ResPool;
import com.adtec.starring.struct.data.Sql;
import com.adtec.starring.util.StringTool;
import com.nxy.cpfsfe.config.CpfsFeAllConfig;
import com.wangyin.rediscluster.client.CacheClusterClient;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * <p>RedisParm</p>
 * <p>Redis参数</p>
 * <p>Copyright: Copyright (c) 2017</p> 
 * <p>Company: 北京先进数通信息技术股份公司</p> 
 * @author  gongxl
 * @version 1.0 2018年4月10日 gongxl
 * <p>          修改者姓名 修改内容说明</p>

 */
public class RedisParm {
    // 本类所有日志存放文件名
    private static final String LOG_FILE = "RedisParm.log";

    /**
     * 根据规则序号查询商户手续费规则
     * @param tpId
     * @param baseDos
     * @param rlNo
     * @return 规则名称|规则代码（百分值）|固定手续费|最低手续费|最高手续费
     */
    public static String qryMertFeRlCache(String tpId, IBaseDos baseDos, String rlNo) {
        String key = "MERT_FE_FL_" + rlNo;
        // TrcLog.log(LOG_FILE,"查询商户手续费规缓存，规则序号:%s，KEY值：%s", rlNo, key);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (rtnVal == null) {
            TrcLog.log(LOG_FILE, "Redis未查到商户手续费规则，从T_MERT_FE_RULE表里查...");
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from T_MERT_FE_RULE where RL_SER_NO='").append(rlNo).append("' and STAT_CD='00'");
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), "T_MERT_FE_RULE");
                CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, "T_MERT_FE_RULE");
                if (num > 0) {
                    String[] eleArr = new String[] { "RL_NM", "RL_CD", "FIX_FE", "LOW_FE", "TALST_FE" };
                    for (int i = 0; i < eleArr.length; i++) {
                        String eleVal = tblSdo.getValue(eleArr[i]) + "";
                        rtnVal = i == 0 ? eleVal : (rtnVal + "|" + eleVal);
                       /* if(i == 0)
                        	rtnVal = eleVal;
                        else
                        	rtnVal += "|" + eleVal;*/
                    }
                    TrcLog.log(LOG_FILE, "从T_MERT_FE_RULE表里查到，记录到Redis...");
                    CpfsFeAllConfig.jedisCluster.set(key, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "T_MERT_SETL_RULE表中未找到记录，sql：%s", sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
     * 将Redis里的手续费规则删除
     * <p>商户手续费规则更新后，执行本函数删除Redis缓存，下次调查询时将重新从表里查</p>
     * @param rlNo
     */
    public static void delMertFeRlCache(String rlNo, String asscOEcd) {
        String key = "MERT_FE_FL_" + asscOEcd + "_" + rlNo;
        TrcLog.log(LOG_FILE, "删除商户手续费规，规则序号:%s，KEY值：%s", rlNo, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }

    /**
     * 查询商户结算规则缓存
     * @param tpId
     * @param baseDos
     * @param rlNo

     * @return 总数|规则名称1|最大金额1|结算方式代码1|周期代码1|周期值1|规则名称2|最大金额2|结算方式代码2|周期代码2|周期值2|...
     */
    public static String qryMertStlRlCache(String tpId, IBaseDos baseDos, String asscOEcd, String rlNo) {
        String key = "MERT_STL_METH_" + asscOEcd + "_" + rlNo;
        // TrcLog.log(LOG_FILE,"查询商户结算规则，规则序号:%s，KEY值：%s", rlNo, key);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (rtnVal == null) {
            TrcLog.log(LOG_FILE, "Redis未查到商户结算规则，从T_MERT_SETL_RULE表里查...");
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from T_MERT_SETL_RULE where ASSC_O_ECD='").append(asscOEcd).append("' and RL_SER_NO='").append(rlNo).append("' and STAT_CD='00' order by MAX_AMT");
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), "T_MERT_SETL_RULE");
                if (num > 0) {
                    rtnVal = num + "";
                    String[] eleArr = new String[] { "RL_NM", "MAX_AMT", "SETL_MTHD_CD", "CYC_CD", "CYC_VAL" };
                    for (int i = 0; i < num; i++) {
                    	CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, "T_MERT_SETL_RULE", i);
                        for (int j = 0; j < eleArr.length; j++) {
                            String eleVal = tblSdo.getValue(eleArr[j]) + "";
                            rtnVal = rtnVal + "|" + eleVal;
                        }
                    }
                    TrcLog.log(LOG_FILE, "从T_MERT_SETL_RULE表里查到，记录到Redis...");
                    CpfsFeAllConfig.jedisCluster.set(key, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "T_MERT_SETL_RULE表中未找到记录，sql：%s", sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
    * 将Redis里的商户结算规则缓存删除
    * <p>商户结算规则更新后，执行本函数删除Redis缓存，下次调查询时将重新从表里查</p>
    * @param rlNo
    */
    public static void delMertStlRlCache(String rlNo) {
        String key = "MERT_STL_METH_" + rlNo;
        TrcLog.log(LOG_FILE, "删除商户结算规则，规则序号:%s，KEY值：%s", rlNo, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }

    /**
    * 查询手续费分润规则缓存
    * @param tpId
    * @param baseDos

    * @return 规则序号|规则名称|分润模式代码|周期代码|周期值|分润值|发卡手续费规则|服务手续费规则|受理手续费规则|通道手续费|分润最高级标志
    */
    public static String qryFeShrPftRlCache(String tpId, IBaseDos baseDos, String asscOEcd, String pymtChnlCd) {
        String key = "FE_SHRPFT_RL_" + asscOEcd + "_" + pymtChnlCd;
        // TrcLog.log(LOG_FILE,"查询手续费分润规则，合作机构代码:%s，渠道:%s，KEY值：%s", asscOEcd,
        // pymtChnlCd, key);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (rtnVal == null) {
            TrcLog.log(LOG_FILE, "Redis未查到手续费分润规则，从T_MERT_BRCH_SHRPFT_RL表里查...");
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from T_MERT_BRCH_SHRPFT_RL where ASSC_O_ECD='").append(asscOEcd).append("' and PYMT_CHNL_CD='").append(pymtChnlCd).append("' and STAT_CD='00'");
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), "T_MERT_BRCH_SHRPFT_RL");
                CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, "T_MERT_BRCH_SHRPFT_RL");
                if (num > 0) {
                    String[] eleArr = new String[] { "RL_SER_NO", "RL_NM", "FSPLTG_PATRN_CD", "CYC_CD", "CYC_VAL", "FSVAL", "ISS_CRD_FE_RL", "SRV_FE_RL", "ACPT_FE_RL", "CHNL_FE_RL", "FSPLTG_HIGH_FLG" };
                    for (int i = 0; i < eleArr.length; i++) {
                        String eleVal = tblSdo.getValue(eleArr[i]) + "";
                        rtnVal = i == 0 ? eleVal : (rtnVal + "|" + eleVal);
                    }
                    TrcLog.log(LOG_FILE, "从T_MERT_BRCH_SHRPFT_RL表里查到，记录到Redis...");
                    CpfsFeAllConfig.jedisCluster.set(key, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "T_MERT_BRCH_SHRPFT_RL表中未找到记录，sql：%s", sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
    * 将Redis里的手续费分润规则缓存删除
    * <p>手续费分润规则更新后，执行本函数删除Redis缓存，下次调查询时将重新从表里查</p>

    */
    public static void delFeShrPftRlCache(String asscOEcd, String pymtChnlCd) {
        String key = "FE_SHRPFT_RL_" + asscOEcd + "_" + pymtChnlCd;
        TrcLog.log(LOG_FILE, "删除手续费分润规则，合作机构代码:%s，渠道:%s，KEY值：%s", asscOEcd, pymtChnlCd, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }

    /**
     * 查询商户参数规则缓存
     * @param tpId
     * @param baseDos
     * @param rlNo
     * @param TAmt
     * @return 参数规则名称|借记账户手续费规则序号|贷记账户手续费规则序号
     */
    public static String qryMertParaRlCache(String tpId, IBaseDos baseDos, String asscOEcd, String rlNo, String pymtChnlCd, String servTypcd) {
        String key = "MERT_PARA_RL_" + asscOEcd + "_" + rlNo + "_" + pymtChnlCd + "_" + servTypcd;
        // TrcLog.log(LOG_FILE,"查询商户参数规则，合作机构代码:%s，规则序号:%s，渠道:%s，服务类型:%s，KEY值：%s",
        // asscOEcd, rlNo, pymtChnlCd, servTypcd, key);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (rtnVal == null) {
            TrcLog.log(LOG_FILE, "Redis未查到商户参数规则缓存，从T_MERT_PARA_RULE表里查...");
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from T_MERT_PARA_RULE where ASSC_O_ECD='").append(asscOEcd).append("' and PARM_RL_SER_NO='").append(rlNo).append("' and PYMT_CHNL_CD='").append(pymtChnlCd).append("' and SERV_TYPCD='").append(servTypcd).append("' and STAT_CD='00'");
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), "T_MERT_PARA_RULE");
                CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, "T_MERT_PARA_RULE");
                if (num > 0) {
                    String[] eleArr = new String[] { "PARM_RL_NM", "DEBT_CARD_FE_RLSERNO", "CRDT_CARD_FE_RLSERNO" };
                    for (int i = 0; i < eleArr.length; i++) {
                        String eleVal = tblSdo.getValue(eleArr[i]) + "";
                        rtnVal = i == 0 ? eleVal : (rtnVal + "|" + eleVal);
                    }
                    TrcLog.log(LOG_FILE, "从T_MERT_PARA_RULE表里查到商户参数规则缓存，记录到Redis...");
                    CpfsFeAllConfig.jedisCluster.set(key, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "T_MERT_PARA_RULE表中未找到记录，sql：%s", sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
    * 将Redis里的商户参数规则缓存删除
    * <p>商户参数规则更新后，执行本函数删除Redis缓存，下次调查询时将重新从表里查</p>
    * @param rlNo
    */
    public static void delMertParaRlCache(String asscOEcd, String rlNo, String pymtChnlCd, String servTypcd) {
        String key = "MERT_PARA_RL_" + asscOEcd + "_" + rlNo + "_" + pymtChnlCd + "_" + servTypcd;
        TrcLog.log(LOG_FILE, "删除商户参数规则，合作机构代码:%s，规则序号:%s，渠道:%s，服务类型:%s，KEY值：%s", asscOEcd, rlNo, pymtChnlCd, servTypcd, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }
    
    /**
     * 查询商户经营类目缓存
     * @param tpId
     * @param baseDos
     * @param catgCd    类目代码
     * @return 类目名称|类目级别|上级类目代码|微信类目代码|支付宝类目代码|其他类目代码
     */
    public static String qryMertMngCatgCache(String tpId, IBaseDos baseDos, String catgCd) {
        String key = "MERT_Mng_CATG_" + catgCd;
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (StringTool.isNullOrEmpty(rtnVal)) {
            String tblNm = "T_MERT_MNG_CATG";
            TrcLog.log(LOG_FILE, "Redis未查到商户经营类目缓存，从%s表里查...", tblNm);
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select * from ").append(tblNm).append(" where ASSC_O_ECD='").append(PubBean.CENT_O_ECD).append("' and CATG_CD='").append(catgCd).append("' and STAT_CD='00'");
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), tblNm);
                CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, tblNm);
                if (num > 0) {
                    String[] eleArr = new String[] {"CATG_NM","CATG_LV","HIGHER_CAT_CD","WCHT_CATG_CD","ALPY_CATG_CD","OTS_CATG_CD"};
                    for (int i = 0; i < eleArr.length; i++) {
                        String eleVal = tblSdo.getValue(eleArr[i]) + "";
                        rtnVal = i == 0 ? eleVal : (rtnVal + "|" + eleVal);
                    }
                    TrcLog.log(LOG_FILE, "从%s表里查到商户经营类目缓存，记录到Redis...", tblNm);
                    CpfsFeAllConfig.jedisCluster.set(key, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "%s表中未找到记录，sql：%s", tblNm, sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
    * 将Redis里的商户经营类目缓存删除
    * <p>商户经营类目更新后，执行本函数删除Redis缓存，下次调查询时将重新从表里查</p>

    */
    public static void delMertMngCatgCache(String catgCd) {
        String key = "MERT_Mng_CATG_" + catgCd;
        TrcLog.log(LOG_FILE, "删除商户经营类目，类目代码:%s，KEY值：%s", catgCd, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }
    
    /**
     * 根据机构查询相关信息
     * @param tpId
     * @param baseDos
     * @param jc
     * @param assc
     * @param element 
     * @return 机构|微信appid|微信商户号|微信渠道商户号|微信支付渠道介质|支付宝appid|支部宝机构pid|支付宝支付渠道介质|
     */
	public static String getAppIdByAssc(String tpId, IBaseDos baseDos, CacheClusterClient jc, String assc, String element, String procTyp) {
		//JedisCluster jc = (JedisCluster) SpringUtil.getBean("redisCluster");
		//String assc = (String) EPOper.get(tpId, "ReqBean.head.servInitrBrch");
		String rdsKey = "T_MERT_ASSC_ACCT_" + assc + "_" + procTyp;
		String rtnVal = jc.get(rdsKey);
		if (StringTool.isNullOrEmpty(rtnVal)){
			String sql = "SELECT * FROM T_MERT_ASSC_ACCT WHERE ASSC_O_ECD= '"+assc+"' AND PROC_TYP = '"+procTyp+"'";
			int num = baseDos.executeSql(Sql.SELECT, sql, element);
			if (num == 0){
				throw new BaseException("PMER001","["+element+"]无合作机构信息,请联系管理员");
			}
			CompSDO sdo = EPOper.getCompSDO(tpId, element);
			String[] eleArr = new String[] {"ASSC_O_ECD", "WX_APPID", "WX_MCHID", "WX_CHANNEL_ID", "WX_PYMT_CHNL_MED", "ALP_APPID", "ALP_PID", "ALP_PYMT_CHNL_MED", "SFTP_PWD"};
			String value = "";
			for (int i = 0; i < eleArr.length; i++) {
				String val = (String) sdo.getValue(eleArr[i]);
				value += val + "|";
			}
			jc.setex(rdsKey, Integer.parseInt(ResPool.configMap.get("redis_key")), value);
			TrcLog.log("redis.log", "rdsKey="+rdsKey+",value="+value);
			rtnVal = value;
		}
		return rtnVal;
	}

	/**
	 * 根据产品编码、科目编号查询相关信息
	 * @param tpId
	 * @param baseDos
	 * @param prodEcd 产品编码
	 * @param subjNo 科目编号
	 * @return SUBJ_NM|SUBJ_LV|UP_SUBJ|SUBJ_TYP|BAL_DIRN
	 */
	public static String getSubjInfoByNo(String tpId, IBaseDos baseDos, String prodEcd, String subjNo) {
        String key = String.format("SAG_SUBJ_INFO_%s_%s", prodEcd, subjNo);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        if (StringTool.isNullOrEmpty(rtnVal)) {
            String tblNm = "TO_SUBJ_INFO";
            TrcLog.log(LOG_FILE, "Redis未查到科目信息缓存，从%s表里查...", tblNm);
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select SUBJ_NM, SUBJ_LV, UP_SUBJ, SUBJ_TYP, BAL_DIRN, VALD_FLG, BEG_DT, FIN_DT from ").append(tblNm).append(" where PROD_ECD='").append(prodEcd).append("' and SUBJ_NO='").append(subjNo).append('\'');
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), tblNm);
                CompSDO tblSdo = (CompSDO) EPOper.getCompSDO(tpId, tblNm);
                if (num > 0) {
                    String[] eleArr = new String[] { "SUBJ_NM","SUBJ_LV","UP_SUBJ","SUBJ_TYP","BAL_DIRN","VALD_FLG", "BEG_DT", "FIN_DT"};
                    for (int i = 0; i < eleArr.length; i++) {
                        String eleVal = tblSdo.getValue(eleArr[i]) + "";
                        rtnVal = i == 0 ? eleVal : (rtnVal + "|" + eleVal);
                    }
                    TrcLog.log(LOG_FILE, "从%s表里查到科目信息缓存，记录到Redis...", tblNm);
                    //jc.set(key, rtnVal);
                    CpfsFeAllConfig.jedisCluster.setex(key, 60*60*24*15, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "%s表中未找到记录，sql：%s", tblNm, sqlBuf.toString());
                }
            } catch (BaseException e) {
                TrcLog.log(LOG_FILE, "数据库异常，可能不是本体系调用..");
            }
        }
        return rtnVal;
    }

    /**
     * 重新加载科目信息缓存
     * @param subjNo
     */
    public static void reloadSubjInfoCache(String tpId, IBaseDos baseDos, String prodEcd, String subjNo) {
        delSubjInfoCache(prodEcd, subjNo);
        getSubjInfoByNo(tpId, baseDos, prodEcd, subjNo);
    }

	/**
	 * 删除科目信息缓存
	 * @param subjNo
	 */
	public static void delSubjInfoCache(String prodEcd, String subjNo) {
        String key = String.format("SAG_SUBJ_INFO_%s_%s", prodEcd, subjNo);
        TrcLog.log(LOG_FILE, "删除科目信息缓存, 产品编码: %s, 科目编号: %s，KEY值：%s", prodEcd, subjNo, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }
	

    /**
     * 根据产品编码、服务代码查询相关信息
     * @param tpId
     * @param baseDos
     * @param prodEcd 产品编码
     * @param srvCd 服务代码
     * @return 
     */
    public static List<CompSDO> getLdgrRl(String tpId, IBaseDos baseDos, String prodEcd, String srvCd) {
        List<CompSDO> list = null;
        String key = String.format("SAG_LDGR_RL_%s_%s", prodEcd, srvCd);
        String rtnVal = CpfsFeAllConfig.jedisCluster.get(key);
        String tblNm = "TP_LDGR_RL";
        String[] eleArr = new String[] { "LDGR_RL_NM", "LDGR_RL_SER_NO", "OCCR_AMT_EXPS", "DRCR_FLG", "SUBJ_NO", "REC_A_FLG", "O_RL_ID", "FIX_O", "VALD_FLG", "BEG_DT", "FIN_DT"};
        if(!StringTool.isNullOrEmpty(rtnVal)) {
            list = new ArrayList<>();
            List<String> lines = Arrays.asList(rtnVal.split("\n"));
            for (String line : lines) {
                CompSDO sdo = new CompSDO(tblNm);
                sdo.setValue("PROD_ECD", prodEcd);
                sdo.setValue("SRV_CD", srvCd);
                PubBean.copy(line.split("\\|"), eleArr, sdo);
                list.add(sdo);
            }
        } else {
            TrcLog.log(LOG_FILE, "Redis未查到核算规则缓存，从%s表里查...", tblNm);
            StringBuffer sqlBuf = new StringBuffer();
            sqlBuf.append("select LDGR_RL_NM, LDGR_RL_SER_NO, OCCR_AMT_EXPS, DRCR_FLG, SUBJ_NO, REC_A_FLG, O_RL_ID, FIX_O, VALD_FLG, BEG_DT, FIN_DT from ").append(tblNm).append(" where PROD_ECD='").append(prodEcd).append("' and SRV_CD='").append(srvCd).append('\'');
            try {
                int num = baseDos.executeSql(Sql.SELLIST, sqlBuf.toString(), tblNm);
                if (num > 0) {
                    //list = new ArrayList<>();
                    list = EPOper.getCompArray(tpId, tblNm);
                    for(int k = 0; k < num; k++) {
                        CompSDO tblSdo = list.get(k);
                        StringBuffer line = new StringBuffer();
                        for (int i = 0; i < eleArr.length; i++) {
                            String eleVal = tblSdo.getValue(eleArr[i]) + "";
                            line.append((i == 0 ? "" : "|") + eleVal);
                        }
                        rtnVal += (k == 0 ? "" : "\n") + line.toString();
                        //list.add(line.toString());
                    }
                    TrcLog.log(LOG_FILE, "从%s表里查到核算规则缓存，记录到Redis...", tblNm);
                    CpfsFeAllConfig.jedisCluster.setex(key, 60 * 60 * 24 * 15, rtnVal);
                    TrcLog.log(LOG_FILE, "[key--value]：[%s--%s]", key, rtnVal);
                } else {
                    TrcLog.log(LOG_FILE, "%s表中未找到记录，sql：%s", tblNm, sqlBuf.toString());
                }
            } catch (Exception e) {
                TrcLog.log(LOG_FILE, "%s", Logable._getStackTrace(e));
            }
        }
        return list;
    }

    /**
     * 重新加载科目信息缓存
     * @param prodEcd 产品编码
     * @param srvCd 服务代码
     */
    public static void reloadLdgrRl(String tpId, IBaseDos baseDos, String prodEcd, String srvCd) {
        delLdgrRl(prodEcd, srvCd);
        getLdgrRl(tpId, baseDos, prodEcd, srvCd);
    }

    /**
     * 删除科目信息缓存
     * @param prodEcd 产品编码
     * @param srvCd 服务代码
     */
    public static void delLdgrRl(String prodEcd, String srvCd) {
        String key = String.format("SAG_LDGR_RL_%s_%s", prodEcd, srvCd);
        TrcLog.log(LOG_FILE, "删除核算规则缓存, 产品编码: %s, 服务代码: %s，KEY值：%s", prodEcd, srvCd, key);
        CpfsFeAllConfig.jedisCluster.del(key);
    }
}
